#include <iostream>
#include <queue>
#include <string>

using namespace std;

class MyStack
{
public:
    MyStack();
    void push(int x);
    int pop();
    int top();
    bool empty();
    int size();

private:
    queue<int> q1;
    queue<int> q2;
};

MyStack::MyStack() {}
void MyStack::push(int x)
{
    q1.push(x);
}
int MyStack::pop()
{
    int length = q1.size() - 1;
    for (int i = 0; i < length; i++)
    {
        int temp = q1.front();
        q2.push(temp);
        q1.pop();
    }
    int result = q1.front();
    q1.pop();
    while (!q2.empty())
    {
        q1.push(q2.front());
        q2.pop();
    }
    return result;
}
int MyStack::top()
{
    return q1.back();
}
bool MyStack::empty()
{
    return q1.empty();
}
int MyStack::size()
{
    return q1.size();
}
int main()
{
    MyStack s;
    for (int i = 1; i <= 10; i++)
    {
        s.push(i);
    }
    cout << "当前栈顶元素：" << s.top() << endl;
    for (int i = 0; i < 5; i++)
    {
        s.pop();
    }
    cout << "出栈5个元素后当前栈顶元素：" << s.top() << endl;
    for (int i = 0; i < 7; i++)
    {
        s.push(i + 11);
    }
    cout << "再入栈7个元素后当前栈内元素：" << endl;
    while (s.empty() != true)
    {
        cout << s.pop() << " ";
    }
    cout << "\n";

    if (s.empty() == true)
    {
        cout << "栈已清空\n";
    }
    else
        cout << "栈未清空\n";

    return 0;
}